package com.yy.good.controller;

import com.yy.good.pojo.Goods;
import com.yy.good.service.impl.GoodsServiceImpl;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 货物表(Goods)表控制层
 *
 * @author yan yi
 * @since 2021-12-04 10:42:14
 * @version 1.0
 */
@RestController
@RequestMapping("/goods")
@Api(value = "货物表(Goods)管理",tags = "货物表(Goods)管理接口API")
@ApiResponses({
        @ApiResponse(code=400,message="请求参数不完整或者错误"),
        @ApiResponse(code=404,message="找不到页面"),
        @ApiResponse(code=405,message="请求方式不正确，比如后台接收是post，但前端请求的是get"),
        @ApiResponse(code=406,message="页面地址和接口名冲突"),
        @ApiResponse(code=415,message="请求格式不正确，前端可能没有把请求头修改为json，也可能前端请求的json对象没有转换为字符串"),
        @ApiResponse(code=500,message="后台服务逻辑错误")
})
public class GoodsController {
    /**
     * 服务对象
     */
    @Resource
    private GoodsServiceImpl goodsServiceImpl;

    /**
     * 对数据进行分页显示
     * @param pageNum  当前页码
     * @param pageSize  显示条数
     * @return 结果
     */
    @RequestMapping(value = "/findByPage", method = RequestMethod.GET)
    @ApiOperation(value = "列表查询分页接口",notes = "列表查询分页接口",httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页码",paramType = "query",dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize",value = "显示条数",paramType = "query",dataType = "Integer")
    })
    public Map<String, Object> findByPage(@RequestParam(name = "pageNum") int pageNum,
                                          @RequestParam(name = "pageSize") int pageSize) {
        return this.goodsServiceImpl.findByPage(pageNum, pageSize);
    }
    
    /**
     * 查询所有数据
     * @return 返回所有数据
     */
    @RequestMapping(value = "/findAll", method = RequestMethod.GET)
    @ApiOperation(value = "查询所有数据接口",notes = "查询所有数据接口",httpMethod = "GET")
    public Map<String, Object> findAll() {
        return this.goodsServiceImpl.findAll();
    }
    
    /**
     * 通过主键删除单条数据
     * @param id 主键
     * @return 单条数据
     */
    @RequestMapping(value = "/deleteById", method = RequestMethod.POST)
    @ApiOperation(value = "根据主键删除一条记录",notes = "根据主键删除一条记录",httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "主键",paramType = "query",dataType = "String",required = true),
    })
    public Map<String, Object> deleteById(@RequestParam("id") String id) {
        return this.goodsServiceImpl.deleteById(id);
    }
    
    /**
     * 通过主键更新单条数据
     * @param goods 一个数据库对应的POJO数据对象
     * @return 单条数据
     */
    @RequestMapping(value = "/updateById", method = RequestMethod.POST)
    @ApiOperation(value = "通过主键更新一条记录",notes = "通过主键更新一条记录",httpMethod = "POST")
    public Map<String, Object> updateById(@RequestBody @ApiParam(name = "goods",value = "pojo模型",required = true) Goods goods) {
        return this.goodsServiceImpl.updateById(goods);
    }
    
    /**
     * 通过一个pojo对象新增单条数据
     * @param goods 一个数据库对应的POJO数据对象
     * @return 返回插入的主键id
     */
    @RequestMapping(value = "/insertOne", method = RequestMethod.POST)
    @ApiOperation(value = "新增一条数据记录",notes = "新增一条数据记录",httpMethod = "POST")
    public Map<String, Object> insertOne(@RequestBody @ApiParam(name = "goods",value = "pojo模型",required = true) Goods goods) {
        return this.goodsServiceImpl.insertOne(goods);
    }

}